package com.quan.weixin.rpc.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.quan.base.common.base.service.support.BaseService;
import com.quan.weixin.rpc.api.WeixinArticleService;
import com.quan.weixin.rpc.api.WeixinArticleTxtService;
import com.quan.weixin.rpc.dao.mapper.WeixinArticleMapper;
import com.quan.weixin.rpc.model.WeixinArticle;
import com.quan.weixin.rpc.model.WeixinArticleTxt;

@Service
public class WeixinArticleServiceImpl extends BaseService<WeixinArticle, Integer> implements WeixinArticleService {

	@Autowired
	private WeixinArticleMapper mapper ;

	@Autowired
	private WeixinArticleTxtService weixinArticleTxtService ;
	
	@Transactional
	@Override
	public WeixinArticle insertArticleContentWrapper(WeixinArticle entity) {
		WeixinArticle article = super.insertSelective(entity) ;
		
		WeixinArticleTxt articleTxt = entity.getArticleTxt() ;
		articleTxt.setArticleId(article.getId());
		this.weixinArticleTxtService.insertSelective(articleTxt) ;
		
		return entity;
	}

	@Override
	public WeixinArticle getArticleWrapper(Integer id) {
		return this.mapper.getArticleWrapper(id);
	}

	@Transactional
	@Override
	public WeixinArticle updateArticleContentWrapper(WeixinArticle entity) {
		super.update(entity) ;
		this.weixinArticleTxtService.updateSelective(entity.getArticleTxt()) ;
		return entity;
	}
}
